require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsTimeBoxHandler ={};
local this = RedDotsTimeBoxHandler;

function RedDotsTimeBoxHandler.init()
    --CloseEvent(Config.EventType.TimeBoxUpdate,this.update);
    CloseEvent(Config.EventType.Fresh_Bag,this.update);
    --ListenEvent(Config.EventType.TimeBoxUpdate,this.update);
    ListenEvent(Config.EventType.Fresh_Bag,this.update);

    return this;
end


--参数 无
function RedDotsTimeBoxHandler.getFlag(...)
    if ...~=nil then
        return Config.RedDotsFlagState.None;
    end
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.TimeBoxAll,false) then
        local timeBoxCount1 = logicMgr.ItemManager.getItemCountbyModelId(CurrencyEnum.TimeBox1);
        local timeBoxCount2 = ItemManager.getItemCountbyModelId(CurrencyEnum.TimeBox2);
        local timeBoxCount3 = ItemManager.getItemCountbyModelId(CurrencyEnum.TimeBox3);
        local timeBoxCount4 = ItemManager.getItemCountbyModelId(CurrencyEnum.TimeBox4);

        local emptytb,count = TimeBoxHandler.GetBoxRemainingState();

        if(timeBoxCount1 > 0 or timeBoxCount2 > 0 or timeBoxCount3 > 0 or timeBoxCount4 > 0 )  and count > 0 then
            return Config.RedDotsFlagState.Needful;
        end
    end
    return Config.RedDotsFlagState.None;
end


function RedDotsTimeBoxHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.TimeBoxAdd);
end